package com.better.frontend.controller.scoreSelection;

import com.alibaba.fastjson.JSONObject;
import com.better.backend.dataComputingService.model.scoreSelection.ScoreSelection;
import com.better.backend.mqReceiverService.calType.calService.CalService;
import com.better.common.base.ServiceResponse;
import com.better.common.jwtauth.secruity.JWTUserDetails;
import com.better.common.utils.ServiceResponseHandle;
import com.better.common.utils.SessionUtils;
import com.better.frontend.Iservice.scoreSelection.ScoreSelectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 设置分数段管理
 * @author tangping
 */
@Api(value = "设置分数段接口", tags = "设置分数段接口")
@RestController
@RequestMapping("api/scoreSelection")
public class ScoreSelectionController {
    private Log logger = LogFactory.getLog(ScoreSelectionController.class);

    @Resource
    private ScoreSelectionService scoreSelectionService;
    @Resource
    private CalService calService;

    /**
     *  批量添加分数段
     * @param scoreSelection
     * @return
     */
    @ApiOperation(value = "批量添加分数段", notes = "批量添加分数段")
    @PostMapping("addScoreSelection")
    public ServiceResponse addScoreSelectionList(@RequestBody ScoreSelection scoreSelection){
        if(logger.isDebugEnabled()){

            logger.debug("传入参数为:"+ JSONObject.toJSONString(scoreSelection));
        }
        return this.scoreSelectionService.addScoreSelection(scoreSelection);
    }

    /**
     *  获得所有的选择等级
     * @return
     */
    @ApiOperation(value = "获取分数段一些常量信息", notes = "获取分数段一些常量信息")
    @GetMapping("getAllSelection")
    public ServiceResponse getAllSelection(String gradeId,String examId){
        return this.scoreSelectionService.getAllSelection(gradeId,examId);
    }

    /**
     *
     * @param subjectId
     * @param examId
     * @return
     */
    @ApiOperation(value = "根据科目id获得分数段信息", notes = "根据科目id获得分数段信息")
    @GetMapping("getSelectionBySubjectId")
    public ServiceResponse getSelectionByCondition(String subjectId,String examId,String gradeId){
        return this.scoreSelectionService.getSelectionByCondition(subjectId,examId,gradeId);
    }
    /**
     *
     * @param subjectId
     * @param examId
     * @return
     */
    @ApiOperation(value = "计算分数段", notes = "计算分数段")
    @GetMapping("publishScoreSegement")
    public ServiceResponse publishScoreSegement(String examId,String gradeId){
        return this.calService.calScoreSelection(examId,gradeId);
    }

    /**
     *  根据考试id 获得对应的考试信息
     * @param examId
     * @return
     */
    @ApiOperation(value = "获取科目以及分数信息" ,notes = "获取科目以及分数信息")
    @GetMapping("listSubjectList")
    public ServiceResponse listSubjectList(String examId){
        return this.scoreSelectionService.listSubjectList(examId);
    }

}
